package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.io.IOException;

public class ListPage extends Utils {
    private static String URL = "http://8.137.19.140:9090/blog_list.html";

    public ListPage() {
        super(URL);
    }

    /**
     * 检查个人信息板块
     * @throws InterruptedException
     */
    public void checkInfo() throws InterruptedException {
        driver.findElement(By.cssSelector("body > div.container > div.left > div > img"));
        driver.findElement(By.cssSelector("body > div.container > div.left > div > h3"));

        //进入链接
        driver.findElement(By.cssSelector("body > div.container > div.left > div > a")).click();
        //这个跳转有延迟 加上等待就行了
        Thread.sleep(2000);
        //返回列表界面
        driver.navigate().back();
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(4) > span:nth-child(1)"));
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(4) > span:nth-child(2)"));
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(1)"));
        driver.findElement(By.cssSelector("body > div.container > div.left > div > div:nth-child(5) > span:nth-child(2)"));
    }

    /**
     * 检查列表页面
     * @throws InterruptedException
     */
    public void checkList() throws InterruptedException, IOException {
        String title = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > div.title")).getText();
        String date = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > div.date")).getText();
        String content = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > div.desc")).getText();
        String button = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > a")).getText();
//        System.out.println("title :" + title);

        assert !title.isEmpty();
        assert !date.isEmpty();
        assert !content.isEmpty();
        assert button.equals("查看全文>>");
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());

        //检查跳转详情页
        driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(2) > a")).click();
        Thread.sleep(1000);
        String jumpTitle = driver.findElement(By.cssSelector("body > div.container > div.right > div > div.title")).getText();
//        System.out.println("jumpTitle :" + jumpTitle);
        assert title.equals(jumpTitle);

        //获取当前详情页的路径
        detailUrl = driver.getCurrentUrl();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }

    /**
     * 检查菜单栏板块
     * @throws InterruptedException
     */
    public void checkMenu() throws InterruptedException, IOException {
        //点击主页
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(4)")).click();
        assert driver.getCurrentUrl().equals(URL);
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击写博客
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();
        driver.findElement(By.cssSelector("#submit"));
        Thread.sleep(3000);
        driver.navigate().back();
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
        //点击注销
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(6)")).click();
        driver.findElement(By.cssSelector("body > div.container-login > div > h3"));
        ScreenShot(Thread.currentThread().getStackTrace()[1].getMethodName());
    }
}
